package com.awesumgames.awesum.layouts;

import android.opengl.Matrix;

import com.awesumgames.awesum.AwesumGlobal.Awesum;
import com.awesumgames.awesum.Game;
import com.awesumgames.awesum.RunnableTree;
import com.awesumgames.awesum.sprites.Sprite;
import com.awesumgames.awesum.sprites.SpriteBase;

public class Layout2dDefault extends RunnableTree {
	public float height, width;
	private float safeMargin;
	public Layout2dDefault(float h, int safe) {
		//h = amount by which to divide up the screen height. width gets based on the screen ratio
		//safe = % of the screen on each edge that'll be a margin for this layout
		
		float sh = (float)Game.screenHeight, sw = (float)Game.screenWidth;
		
		height = h;
		width = sw / sh * (float)h;
		
		float innerHeight = sh - (sh * ((float)safe * 2f / 100f));
		safeMargin = ((float)h / innerHeight * sh - h) / 2f;
	}
	public Layout2dDefault(float w, float h, int safe) {
		float sh = (float)Game.screenHeight, sw = (float)Game.screenWidth;
		
		width = w;
		height = h;
		
		float innerHeight = sh - (sh * ((float)safe * 2f / 100f));
		safeMargin = ((float)h / innerHeight * sh - h) / 2f;
	}
	
	public void add(SpriteBase s) {
		children.add(s);
	}
	
	public void draw() {
		Matrix.orthoM(Game.projectionMatrix, 0, -safeMargin, width + safeMargin, height + safeMargin, -safeMargin, 0, 10);
		//Matrix.orthoM(Game.projectionMatrix, 0, 0, width, 0, height, 0, 10);
		//Awesum.debug("call to layout draw");
		super.draw();
	}

}
